/*****************************************************************
 MYD Engine v0.1

 file: tstgame.cpp
 created: 20/06/09
*****************************************************************/
#include "tstgame.h"

//-------------------------------------------------------------------
tstgame::tstgame(HINSTANCE hInstance)
:
Game(hInstance),
m_pkShape(new Shape(Shape::SQUARE, Shape::RED)),
m_pkSprite(new Sprite()),
m_pkGhost(new Sprite()),
m_pkTilemap(new Tilemap()),
cube(new Mesh3d()),
viewX(0),
viewY(0)
{
}
//-------------------------------------------------------------------------------------
tstgame::~tstgame(void)
{
	delete m_pkShape; m_pkShape = NULL;
	delete m_pkSprite; m_pkSprite = NULL;
	delete m_pkGhost; m_pkGhost = NULL;
	delete m_pkTilemap; m_pkTilemap = NULL;
}
//-------------------------------------------------------------------------------------

bool tstgame::onInit()
{
	Importer* pkImporter = getImporter();

	//set shapes
	m_pkShape->setDim(100,100);
	m_pkShape->setPos(50,200,1);

	//set pacman
	m_pkSprite = pkImporter->createSpriteFromFile("../../res/pacman.bmp",
												 21,2,12,14, 
												 D3DCOLOR_XRGB(255, 255, 255));

	m_pkSprite->setName("pacman");
	m_pkSprite->setDim(48,56);
	m_pkSprite->setPos(100,-150,-1);
	m_pkSprite->setCollisionable(true);
	m_pkSprite->setAnimation("../../res/anim.def", true);
	m_pkSprite->toggleAnimation(true);
	
	//add it to the scene
	addEntity(m_pkSprite);

	//set ghost
	m_pkGhost = pkImporter->createSpriteFromFile("../../res/pacman.bmp",
												2,21,14,12, 
												D3DCOLOR_XRGB(255, 255, 255));
	m_pkGhost->setName("fantasma azul");
	m_pkGhost->setDim(56,48);
	m_pkGhost->setPos(100,100,0);
	
	//add it to the scene
	addEntity(m_pkGhost);

	cube->setPos(100,100,0);
	cube->setDim(100,100);

	/*/add shape
	addEntity(m_pkShape);

	//set tilemap
	m_pkTilemap = pkImporter->createSpriteMap("../../res/mspacman-01.amf",-200,200);
	//m_pkTilemap->SetPos(0,0);
	//addEntity(m_pkTilemap);
	
	for(int i=0; i<m_pkTilemap->tilesVector.size();i++)
		addEntity(m_pkTilemap->tilesVector[i]);

	//set mesh
	tstmesh.createTeapot(wn_renderer->D3Ddevice);
	//addEntity(&tstmesh);*/

	pkImporter->importXFile("../../res/airplane 2.x", tstmesh3d, wn_renderer->D3Ddevice);

	return true;
}
//-------------------------------------------------------------------------------------
bool tstgame::onLoop()
{
//-------------------------------------------------------------------------------------
	//tstmesh.draw(*wn_renderer);
	//wn_renderer->D3Ddevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
	cube->draw(*wn_renderer);
	tstmesh3d.draw(*wn_renderer);
//-------------------------------------------------------------------------------------
	if(input->GetKeyDown(DIK_LEFT))
	{
		wn_camera.Strafe(-10.0f);
	}

	if(input->GetKeyDown(DIK_RIGHT))
	{
		wn_camera.Strafe(10.0f);
	}

	if(input->GetKeyDown(DIK_UP))
	{
		wn_camera.Walk(10.0f);
	}

	if(input->GetKeyDown(DIK_DOWN))
	{
		wn_camera.Walk(-10.0f);
	}

	return false;
}
//-------------------------------------------------------------------------------------
bool tstgame::onDeinit()
{
	return true;
}